/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.groupofdoom.support;

import edu.chl.groupofdoom.beans.TorrentBean;
import edu.chl.groupofdoom.beans.UserBean;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;

/**
 * 
 *
 * @author Martin
 */
public class SupportClass {

    /**
     * Returns the current UserBean
     * This object is session scoped
     * 
     * @return
     */

    public static UserBean getUserBean() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        Application app = ctx.getApplication();
        ELContext ectx = ctx.getELContext();
        ExpressionFactory ef = app.getExpressionFactory();
        ValueExpression ve = ef.createValueExpression(ectx, "#{UserBean}", UserBean.class);
        UserBean mUserBean = (UserBean) ve.getValue(ectx);

        return mUserBean;
    }
    /**
     * Returns the current TorrentBean
     * This object is request scoped
     * @return
     */
    public static TorrentBean getTorrentBean() {
        FacesContext ctx = FacesContext.getCurrentInstance();
        Application app = ctx.getApplication();
        ELContext ectx = ctx.getELContext();
        ExpressionFactory ef = app.getExpressionFactory();
        ValueExpression ve = ef.createValueExpression(ectx, "#{TorrentBean}", TorrentBean.class);
        TorrentBean mTorrentBean = (TorrentBean) ve.getValue(ectx);

        return mTorrentBean;
    }
}
